package com.demo.richText.controller;

import com.demo.richText.framework.CommonController;
import com.demo.richText.util.FileUtil;
import com.demo.richText.util.ResultResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Description 富文本操作
 * @Author 小乌龟
 * @Date 2022/8/29 19:55
 */
@RestController
@Api(tags = "富文本资源处理")
@RequestMapping("/rich-text")
public class UploadController extends CommonController {
    @PostMapping("/uploadAPicFile")
    @ApiOperation("图片下载")
    public ResultResponse<String> uploadRichImg(@RequestParam("richPic") MultipartFile file) {
        return process(() -> FileUtil.uploadImage(file, "richPic"));

    }

    @PostMapping("/deleteAFile")
    @ApiOperation("删除文件数组")
    public ResultResponse<String> deleteAPic(@RequestBody List<String> fileList) {
        return process(() -> {
                    fileList.forEach(FileUtil::deleteFile);
                    return "删除文件成功";
                }
        );

    }

    @PostMapping("/uploadAVideoFile")
    @ApiOperation("视频下载")
    public ResultResponse<String> uploadRichVideo(@RequestParam("richVideo") MultipartFile file) {
        return process(() -> FileUtil.uploadVideo(file, "richVideo"));

    }

}
